
import pygame
import mods.CrystalLib
import mods.printlib
from random import randint as ri

isAlive = True
def player_speed():
    return 9
def enemy_speed_1():
    return 12
# map generator
def map_g_void_prob():
    return 20
def map_g_soft_prob():
    return 48 #56
def map_g_isVoid(row, column):
    if(1<=row<=5 and 1<=column<=5)or(9<=row<=13 and 14<=column<=18)or(row==3 and 6<=column<=9)or(row==11 and 9<=column<=13)or column==9:
        return True
    else:
        return False
def item_ender_pearl_distance():
    return 5

color_e1 = (255, 6, 255)
color_e2 = (0xfd, 0xe3, 0x02)
color_e3 = (0xc5, 0xfb, 0x46)
def ask_e_color(ID):
    if ID == 1:
        return color_e1
    elif ID == 2:
        return color_e2
    elif ID == 3:
        return color_e3
    else:
        mods.CrystalLib.print_warning('cfg: Error ID at stack ask_e_color')
        return (60,60,60)

TNTPower = 3
FPS_limit = 6000 # 20 - 1000

def config2(screen):
    global TNTPower, FPS_limit
    c1, c2, c21 = mods.CrystalLib.RandomColor(), mods.CrystalLib.RandomColor(), mods.CrystalLib.RandomColor()
    
    while True:
        mods.CrystalLib.FPS.tick(8)
        pygame.draw.rect(screen, (255, 255, 255), (0, 0, 1199, 900))
        
        mods.printlib.xyprint('TNT Power', color = c1, place = ('left', 1))
        data = mods.printlib.F.render(f'{TNTPower}', True, c1)
        screen.blit(data, (520, 60))
        mods.Iris.draw_image('reduce', (460, 40))
        mods.Iris.draw_image('add', (550, 40))
        
        fps_show = FPS_limit
        if fps_show > 1000:
            fps_show = '无限制'
        #elif fps_show < 30:
        #    fps_show = 30 # '垂直同步'
        mods.printlib.xyprint(f'FPS:  {fps_show}', color = c2, place = ('left', 2))
        pygame.draw.rect(screen, c2, (460, 110, 196, 10))
        pygame.draw.circle(screen, c21, (mods.CrystalLib.cint(460 + (FPS_limit - 20) * 2 / 10), 115), 15)
        
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return
            if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                return
                break;
            if event.type == pygame.MOUSEBUTTONDOWN:
                xpos, ypos = event.pos[0], event.pos[1]
                if 460 < xpos < 500 and 40 < ypos < 80:
                    if TNTPower > 3:
                        TNTPower -= 1
                if 550 < xpos < 590 and 40 < ypos < 80:
                    if TNTPower < 7:
                        TNTPower += 1
                
                if 450 < xpos < 670 and 100 < ypos < 130:
                    if 450 < xpos <= 460:
                        FPS_limit = 60
                    elif xpos >= 656:
                        FPS_limit = 6000
                    else:
                        #FPS_limit = mods.CrystalLib.cint((xpos - 460)/ 2 * 10 + 20)
                        FPS_limit = mods.CrystalLib.cint((xpos - 460)* 1.153846 + 30) #240103
                
        pygame.display.flip()

FriendFire = True
PowerIncrease = True
DoEnemyDisperse = True
SimplifyDebuggingInformation = False
SimplifyOutputInformation = True
DoCapacityIncrease = True
UseEulaDistance = True
DoGoalIncrease = True
EnableVerticalSynchronization = False
EnableTNTBreakBlock = True
DoEquipmentShield = True # Automatic equipment shield

def change_config(screen):
    global FriendFire, PowerIncrease, DoEnemyDisperse, SimplifyDebuggingInformation, SimplifyOutputInformation, DoCapacityIncrease
    global UseEulaDistance, DoGoalIncrease, EnableVerticalSynchronization, EnableTNTBreakBlock, DoEquipmentShield
    pygame.display.update()
    c1, c2, c3 = (ri(10,250), ri(10, 250), ri(10, 250)), (ri(10,250), ri(10, 250), ri(10, 250)), (ri(10,250), ri(10, 250), ri(10, 250))
    c4, c5, c6 = (ri(10, 250), ri(10, 250), ri(10, 250)), mods.CrystalLib.RandomColor(), mods.CrystalLib.RandomColor()
    c7, c8, c9 = mods.CrystalLib.RandomColor(), mods.CrystalLib.RandomColor(), mods.CrystalLib.RandomColor()
    c10, c11 = mods.CrystalLib.RandomColor(), mods.CrystalLib.RandomColor()
    
    while True:
        mods.CrystalLib.FPS.tick(8)
        pygame.draw.rect(screen, (255,255,0xff), (0,0,1199, 900))
        mods.printlib.xyprint('FriendFire', color = c1, place = ('left', 1)) #60
        mods.printlib.xyprint('DoPowerIncrease', color = c2, place = ('left', 2))#110
        mods.printlib.xyprint('DoEnemyDisperse', color = c3, place = ('left', 3))#160
        mods.printlib.xyprint('SimplifyDebuggingInfo', color = c4, place = ('left', 4))
        mods.printlib.xyprint('SimplifyOutputInfo', color = c5, place = ('left', 5))
        mods.printlib.xyprint('DoCapacityIncrease', color = c6, place = ('left', 6))
        mods.printlib.xyprint('Use Euler Distance', color = c7, place = ('left', 7))
        mods.printlib.xyprint('Automatically increase score', color = c8, place = ('left', 8))
        mods.printlib.xyprint('Enable vertical synchronization', color = c9, place = ('left', 9))
        mods.printlib.xyprint('Enable TNT break block', color = c10, place = ('left', 10))
        mods.printlib.xyprint('Automatic equipment shield', color = c11, place = ('left', 11))
        
        pygame.draw.rect(screen, (0, 255, 255), (400, 40, 40, 40))
        pygame.draw.rect(screen, (0, 255, 255), (400, 90, 40, 40))
        pygame.draw.rect(screen, (0, 255, 255), (400, 140, 40, 40))
        pygame.draw.rect(screen, (0, 255, 255), (400, 190, 40, 40))
        pygame.draw.rect(screen, (0, 255, 255), (400, 240, 40, 40))
        pygame.draw.rect(screen, (0, 255, 255), (400, 290, 40, 40))
        pygame.draw.rect(screen, (0, 255, 255), (400, 340, 40, 40))
        pygame.draw.rect(screen, (0, 255, 255), (400, 390, 40, 40))
        pygame.draw.rect(screen, (0, 255, 255), (400, 440, 40, 40))
        pygame.draw.rect(screen, (0, 255, 255), (400, 490, 40, 40))
        pygame.draw.rect(screen, (0, 255, 255), (400, 540, 40, 40))
        
        pygame.draw.rect(screen, (255,255,255), (405, 45, 30, 30))
        pygame.draw.rect(screen, (255,255,255), (405, 95, 30, 30))
        pygame.draw.rect(screen, (255,255,255), (405, 145, 30, 30))
        pygame.draw.rect(screen, (255,255,255), (405, 195, 30, 30))
        pygame.draw.rect(screen, (255,255,255), (405, 245, 30, 30))
        pygame.draw.rect(screen, (255,255,255), (405, 295, 30, 30))
        pygame.draw.rect(screen, (255,255,255), (405, 345, 30, 30))
        pygame.draw.rect(screen, (255,255,255), (405, 395, 30, 30))
        pygame.draw.rect(screen, (255,255,255), (405, 445, 30, 30))
        pygame.draw.rect(screen, (255,255,255), (405, 495, 30, 30))
        pygame.draw.rect(screen, (255,255,255), (405, 545, 30, 30))
        
        if FriendFire == True:
            pygame.draw.rect(screen, (0, 255, 255), (410, 50, 20, 20))
        if PowerIncrease == True:
            pygame.draw.rect(screen, (0, 255, 255), (410, 100, 20, 20))
        if DoEnemyDisperse == True:
            pygame.draw.rect(screen, (0, 255, 255), (410, 150, 20, 20))
        if SimplifyDebuggingInformation == True:
            pygame.draw.rect(screen, (0, 255, 255), (410, 200, 20, 20))
        if SimplifyOutputInformation == True:
            pygame.draw.rect(screen, (0, 255, 255), (410, 250, 20, 20))
        if DoCapacityIncrease == True:
            pygame.draw.rect(screen, (0, 255, 255), (410, 300, 20, 20))
        if UseEulaDistance == True:
            pygame.draw.rect(screen, (0, 255, 255), (410, 350, 20, 20))
        if DoGoalIncrease == True:
            pygame.draw.rect(screen, (0, 255, 255), (410, 400, 20, 20))
        if EnableVerticalSynchronization == True:
            pygame.draw.rect(screen, (0, 255, 255), (410, 450, 20, 20))
        if EnableTNTBreakBlock == True:
            pygame.draw.rect(screen, (0, 255, 255), (410, 500, 20, 20))
        if DoEquipmentShield == True:
            pygame.draw.rect(screen, (0, 255, 255), (410, 550, 20, 20))
        
        mods.Iris.draw_image('nextpage', (900, 800))
        mods.Iris.draw_image('ShaderSetting', (900, 850))
        
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return
            if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                return
                break;
            if event.type == pygame.MOUSEBUTTONDOWN:
                xpos, ypos = event.pos[0], event.pos[1]
                if 400 < xpos < 440 and 40 < ypos < 80:
                    FriendFire = False if FriendFire == True else True
                if 400 < xpos < 440 and 90 < ypos < 130:
                    PowerIncrease = False if PowerIncrease == True else True
                if 400 < xpos < 440 and 140 < ypos < 180:
                    DoEnemyDisperse = False if DoEnemyDisperse == True else True
                if 400 < xpos < 440 and 190 < ypos < 230:
                    SimplifyDebuggingInformation = False if SimplifyDebuggingInformation == True else True
                if 400 < xpos < 440 and 240 < ypos < 280:
                    SimplifyOutputInformation = False if SimplifyOutputInformation == True else True
                if 400 < xpos < 440 and 290 < ypos < 330:
                    DoCapacityIncrease = False if DoCapacityIncrease == True else True
                if 400 < xpos < 440 and 340 < ypos < 380:
                    UseEulaDistance = False if UseEulaDistance == True else True
                if 400 < xpos < 440 and 390 < ypos < 430:
                    DoGoalIncrease = False if DoGoalIncrease == True else True
                if 400 < xpos < 440 and 440 < ypos < 480:
                    EnableVerticalSynchronization = False if EnableVerticalSynchronization == True else True
                    if EnableVerticalSynchronization == True:
                        pygame.display.set_mode(size = (1500, 900), vsync = True)
                    else:
                        pygame.display.set_mode(size = (1500, 900), vsync = False)
                if 400 < xpos < 440 and 490 < ypos < 530:
                    EnableTNTBreakBlock = False if EnableTNTBreakBlock == True else True
                if 400 < xpos < 440 and 540 < ypos < 580:
                    DoEquipmentShield = False if DoEquipmentShield == True else True
                
                if 900 < xpos < 1020 and 800 < ypos < 840:
                    config2(screen)
                if 900 < xpos < 1020 and 850 < ypos < 890:
                    mods.Iris.Shader_config_main(screen)
        pygame.display.flip()



